﻿' This is generated Code:
' Class Created by Script @ createclass.aspx
' (c) 2009-2011 Secura Hosting Ltd.  All Rights Reserved.
'
'   GetClientsDetails.vb
'
'   part of WHMCSdotnet (http://whmcsdotnet.wordpress.com)
'
'   Copyright (C) 2009-2011 Mark Castle <markcastle@gmail.com>
'   All rights reserved. 
'   Copyright (C) 2009-2011 Secura Hosting Ltd <code@securahosting.com>.
'   All rights reserved.
' 
'   Redistribution and use in source and binary forms, with or without modification,
'   are permitted provided that the following conditions are met:
' 
'   - Redistributions of source code must  retain  the  above copyright notice, this
'     list of conditions and the following disclaimer.
' 
'   - Redistributions in binary form  must  reproduce the  above  copyright  notice,
'     this list of conditions  and  the  following  disclaimer in  the documentation
'     and/or other materials provided with the distribution.
' 
'   - Neither  the  name  of  Secura Hosting Ltd, Mark Castle  nor the names of  its
'     contributors may be used to endorse or  promote  products  derived  from  this
'     software without specific prior written permission.
' 
'   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
'   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT  NOT  LIMITED TO, THE IMPLIED
'   WARRANTIES  OF  MERCHANTABILITY   AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
'   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
'   ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
'   (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT  OF  SUBSTITUTE  GOODS OR SERVICES;
'   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  HOWEVER  CAUSED AND ON
'   ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
'   (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING  IN  ANY WAY OUT OF THE USE OF THIS
'   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Option Explicit On
Option Strict On

Imports System
Imports System.Reflection
Imports System.Collections
Imports System.Diagnostics


Namespace Secura.WHMCS

    Public Class GetClientsDetails
        Inherits Secura.WHMCS.APIBaseType

        Private Const MODULE_NAME As String = "Secura.WHMCS.GetClientsDetails"

#Region "Properties"

        Private _ClientId As Integer = 0
        Private _Email As String = ""


        ' -----------------------------------------------
        ' -- Properties
        ' -----------------------------------------------

        ''' <summary>
        ''' ClientId Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ClientId() As Integer
            Get
                Return _ClientId
            End Get

            Set(ByVal Value As Integer)
                _ClientId = Value
            End Set
        End Property

        ''' <summary>
        ''' Email Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Email() As String
            Get
                Return _Email
            End Get

            Set(ByVal Value As String)
                _Email = Value
            End Set
        End Property



#End Region

#Region "Public Methods"

        ' -----------------------------------------------
        ' -- Public Methods
        ' -----------------------------------------------



#End Region

#Region "Constructors"

        ' -----------------------------------------------
        ' -- Constructor
        ' -----------------------------------------------	

        ''' <summary>
        ''' New Constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
        End Sub

        Public Sub New(ByVal ClientId As Integer, ByVal Email As String)
            _ClientId = ClientId
            _Email = Email
        End Sub


#End Region

#Region "Private Methods"

        ' -----------------------------------------------
        ' -- Private Methods
        ' -----------------------------------------------
        ' Your Private Methods Go Here.

#End Region

#Region "Supporting Objects"

        ''' <summary>
        ''' Some Utilities used by these classes
        ''' </summary>
        ''' <remarks></remarks>
        Public Class Utilities

            ''' <summary>
            ''' CheckNull Method
            ''' If Item is Nothing then Returns Nothing rather than DbNull
            ''' </summary>
            ''' <param name="Item"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CheckNull(ByVal Item As Object) As Object
                If Item Is System.DBNull.Value Then
                    Return Nothing
                Else
                    Return Item
                End If
            End Function

            ''' <summary>
            ''' CStrEx Method
            ''' A CStr function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CStrEx(ByVal test As Object) As String
                If IsDBNull(test) Then
                    Return ("")
                Else
                    Return CStr(test)
                End If
            End Function

            ''' <summary>
            ''' CBoolEx Method
            ''' A CBool function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CBoolEx(ByVal test As Object) As Boolean
                If IsDBNull(test) Then
                    Return False
                Else
                    Return CBool(test)
                End If
            End Function

            ''' <summary>
            ''' CIntEx Method
            ''' A CInt function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CIntEx(ByVal test As Object) As Integer
                If IsDBNull(test) Then
                    Return 0
                Else
                    Return CInt(test)
                End If
            End Function

        End Class


        ''' <summary>
        ''' A Local debugging object
        ''' </summary>
        ''' <remarks></remarks>
        Class Debug

            Public Enum LogLevel As Integer
                NoLogging = 0
                Normal = 1
                Verbose = 2
                Debug = 3
            End Enum

            ''' <summary>
            ''' A Simple Logging Method
            ''' </summary>
            ''' <param name="Text"></param>
            ''' <param name="Logtype"></param>
            ''' <param name="Level"></param>
            ''' <param name="Success"></param>
            ''' <param name="WriteToEventLog"></param>
            ''' <param name="Filename"></param>
            ''' <param name="WriteToConsole"></param>
            ''' <param name="IncludePrefix"></param>
            ''' <param name="IncludeTime"></param>
            ''' <remarks></remarks>
            Public Shared Sub Log(ByVal Text As String, _
                                      Optional ByVal Logtype As EventLogEntryType = EventLogEntryType.Information, _
                                      Optional ByVal Level As LogLevel = LogLevel.Normal, _
                                      Optional ByVal Success As Boolean = True, _
                                      Optional ByVal WriteToEventLog As Boolean = True, _
                                      Optional ByVal Filename As String = "", _
                                      Optional ByVal WriteToConsole As Boolean = False, _
                                      Optional ByVal IncludePrefix As Boolean = True, _
                                      Optional ByVal IncludeTime As Boolean = True)

                ' Secura.Debug.Log(Text, Logtype, CType(Level, Secura.GetClientsDetails.Debug.LogLevel), Success, WriteToEventLog, Filename, WriteToConsole, IncludePrefix, IncludeTime)
                Trace.Write(LogType.ToString() & ": " & Text, "Secura.WHMCS.GetClientsDetails")

            End Sub

        End Class
#End Region

    End Class

#Region "Collection"

    Public Class GetClientsDetailsCollection
        Inherits Secura.WHMCS.CollectionHelpers.GetClientsDetailsBase.SortableCollectionBase

        Public Sub New()
            MyBase.SortObjectType = GetType(GetClientsDetails)
        End Sub

        ' ------------------------------------------------------------------------
        ' -- Property: Count
        ' -- Gets the number of elements contained in the Collection instance.
        ' -- This property is inherited from CollectionBase and available by default.
        ' ------------------------------------------------------------------------	

        ' ------------------------------------------------------------------------
        ' -- Property: Item
        ' -- Gets or sets the element at the specified index.
        ' ------------------------------------------------------------------------
        Default Public Property Item(ByVal Index As Integer) As GetClientsDetails
            Get
                Return CType(MyBase.List.Item(Index), GetClientsDetails)
            End Get
            Set(ByVal Value As GetClientsDetails)
                MyBase.List.Item(Index) = Value
            End Set
        End Property

        ' ------------------------------------------------------------------------
        ' -- Method: Clear
        ' -- Removes all objects from the CollectionBase instance
        ' -- This Method is inherited from CollectionBase and is available by default.
        ' ------------------------------------------------------------------------	
        'Public Function Clear() As Integer
        '	MyBase.List.Clear
        'End Function


        ' ------------------------------------------------------------------------
        ' -- Method: Add
        ' -- Searches Adds an object to the end of the Collection. 
        ' ------------------------------------------------------------------------	
        Public Function Add(ByVal Item As GetClientsDetails) As Integer
            Return MyBase.List.Add(Item)
        End Function

        ' ------------------------------------------------------------------------
        ' -- Method: IndexOf
        ' -- Searches for the specified Object and returns the zero-based index of 
        ' -- the first occurrence within the entire Collection.
        ' ------------------------------------------------------------------------
        Public Function IndexOf(ByVal Item As GetClientsDetails) As Integer
            Return MyBase.List.IndexOf(Item)
        End Function 'IndexOf

        ' ------------------------------------------------------------------------
        ' -- Method: Insert
        ' -- Inserts an element into the CollectionBase at the specified index. 
        ' ------------------------------------------------------------------------	
        Public Sub Insert(ByVal Index As Integer, ByVal Item As GetClientsDetails)
            MyBase.List.Insert(Index, Item)
        End Sub 'Insert

        ' ------------------------------------------------------------------------
        ' -- Method: Remove
        ' -- Removes the first occurrence of a specific object from the Collection. 
        ' ------------------------------------------------------------------------	
        Public Sub Remove(ByVal Item As GetClientsDetails)
            MyBase.List.Remove(Item)
        End Sub 'Remove

        ' ------------------------------------------------------------------------
        ' -- Method: RemoveAt
        ' -- Removes the first occurrence of a specific object from the Collection. 
        ' ------------------------------------------------------------------------	
        'Public Sub Remove(ByVal Item As GetClientsDetails)
        '	MyBase.List.Remove(Item)
        'End Sub 'Remove

        ' ------------------------------------------------------------------------
        ' -- Method: Contains
        ' -- Determines whether the CollectionBase contains a specific element. 
        ' ------------------------------------------------------------------------
        Public Function Contains(ByVal Item As GetClientsDetails) As Boolean
            ' If value is not of type GetClientsDetails, this will return false.
            Return MyBase.List.Contains(Item)
        End Function 'Contains

    End Class

#End Region

End Namespace

Namespace Secura.WHMCS.CollectionHelpers.GetClientsDetailsBase

#Region " ** Interface Definitions ** "
    Public Interface IGenericComparer
        Inherits IComparer

        'IGeneriComparer Extends IComparer to include ObjectType,
        'SortByName, And SortingOrder Properties

        Property SortObjectType() As System.Type
        Property SortByName() As String
        Property SortDirection() As Integer
    End Interface

    Public Interface ISortable
        'A new interface for the abstract implementation that
        'includes our Sort method

        Property SortObjectType() As System.Type
        Property SortByName() As String
        Property SortDirection() As GenericComparer.SorterDirection

        Sub Sort()
    End Interface
#End Region

    '-----------------------------------------
    '----- Generic Comparer Class
    '----- This Class Implements the IGenericComparer interface
    '-----------------------------------------
#Region " ** GenericComparer Class ** "
    Public NotInheritable Class GenericComparer 'Sealed class
        Implements IGenericComparer

        Public Enum SorterDirection
            Ascending = 0
            Descending = 1
        End Enum

        Private m_SortObjectType As System.Type
        Private m_SortByName As String = ""
        Private m_SortDirection As Integer = 0

        Property SortObjectType() As System.Type Implements IGenericComparer.SortObjectType
            Get
                Return m_SortObjectType
            End Get
            Set(ByVal value As System.Type)
                m_SortObjectType = value
            End Set
        End Property

        Property SortByName() As String Implements IGenericComparer.SortByName
            Get
                Return m_SortByName
            End Get
            Set(ByVal value As String)
                m_SortByName = value
            End Set
        End Property

        Property SortDirection() As Integer Implements IGenericComparer.SortDirection
            Get
                Return m_SortDirection
            End Get
            Set(ByVal value As Integer)
                m_SortDirection = value
            End Set
        End Property

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
            'Basedon the property name we have to get the property info
            Dim oPropertyInfo As PropertyInfo = SortObjectType.GetProperty(m_SortByName)

            'Nowthat we have the property Info we can get the value of each of theproperties
            'castas IComparable objects
            Dim object1 As IComparable = DirectCast(oPropertyInfo.GetValue(x, Nothing), IComparable)
            Dim object2 As IComparable = DirectCast(oPropertyInfo.GetValue(y, Nothing), IComparable)

            'Nowall we have to do is compare the properties with the CompareTo method
            'Inheritedfrom IComparable
            If SortDirection = 0 Then
                Return (object1.CompareTo(object2))
            Else
                Return (object2.CompareTo(object1))
            End If
        End Function

    End Class
#End Region

    '-----------------------------------------
    '----- Abstract Implementation Class -----
    '-----------------------------------------
#Region " ** SortableCollectionBase Class** "
    Public MustInherit Class SortableCollectionBase
        Inherits Collections.CollectionBase
        Implements ISortable

        'Thisclass must be inherited and is our new Collection Class inheritedfrom
        'CollectionBaseand implementing our ISortable interface

        Private m_SortByName As String = ""
        Private m_SortDirection As GenericComparer.SorterDirection
        Private m_SortObjectType As System.Type

        Public Property SortByName() As String Implements ISortable.SortByName
            Get
                Return m_SortByName
            End Get
            Set(ByVal value As String)
                m_SortByName = value
            End Set
        End Property

        Public Property SortDirection() As GenericComparer.SorterDirection Implements ISortable.SortDirection
            Get
                Return m_SortDirection
            End Get
            Set(ByVal value As GenericComparer.SorterDirection)
                m_SortDirection = value
            End Set
        End Property

        Public Property SortObjectType() As System.Type Implements ISortable.SortObjectType
            Get
                Return m_SortObjectType
            End Get
            Set(ByVal value As System.Type)
                m_SortObjectType = value
            End Set
        End Property

        Overridable Sub Sort() Implements ISortable.Sort
            If m_SortByName = "" Then Throw New Exception("First Set SortByName")
            If m_SortObjectType Is Nothing Then Throw New Exception("First Set theSortObjectType")

            Dim oSorter As IGenericComparer = New GenericComparer()
            oSorter.SortObjectType = m_SortObjectType
            oSorter.SortByName = m_SortByName
            oSorter.SortDirection = CInt(m_SortDirection)

            InnerList.Sort(oSorter)
        End Sub

    End Class
#End Region

End Namespace